package IO_Stream;

import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

public class Properties_study {
    public static void main(String[] args) throws IOException {
        Properties prop = new Properties();
        prop.setProperty("low","16");
        prop.setProperty("high","18");
        prop.setProperty("dog","19");
        /*Set<String> set = prop.stringPropertyNames();
//将properties集合中的键key取出，存放到Set集合中
        for (String s : set) {
            String value = prop.getProperty(s);
            System.out.println("key:"+s+" value:"+value);
        }*/

        FileWriter fw = new FileWriter("C:\\Users\\啦啦啦\\Desktop\\f.txt",true);
//#my data
//#Mon Mar 29 15:51:30 CST 2021
//打印出来的注释
        prop.store(fw,"my data");
//将prop中的数据输入到fw中
        prop.store(new FileOutputStream("C:\\Users\\啦啦啦\\Desktop\\f.txt",true),"");
//使用字节流的话，写中文会出现乱码
        Properties prop2 = new Properties();
        prop2.load(new FileReader("C:\\Users\\啦啦啦\\Desktop\\f.txt"));
//使用load方法将文件中的键值对读取到prop中
//如果有用#进行注释的话，键值对就不会被读取到prop中
        Set<String> set2 = prop2.stringPropertyNames();
        for (String s : set2) {
            String value = prop2.getProperty(s);
            System.out.println("key:"+s+" value:"+value+"PROP2");
        }
        fw.close();
    }
}
